package com.fly.controller;
import com.fly.common.ApplicationContextHelper;
import com.fly.common.JsonData;
import com.fly.dao.SysAclModuleMapper;
import com.fly.exception.ParamException;
import com.fly.model.SysAclModule;
import com.fly.param.TestVo;
import com.fly.util.BeanValidator;
import com.fly.util.JsonMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/test")
@Slf4j
public class TestController {

    @RequestMapping("/hello.json")
    @ResponseBody
    public JsonData hello() {
        log.info("hello");
        return JsonData.success("hello, permission");
    }
    @RequestMapping("/validate.json")
    @ResponseBody
    public JsonData validate(TestVo vo) throws ParamException {
        log.info("validate");
//        try {
//            Map<String, String> map = BeanValidator.validateObject(vo);
//            if (map!=null&&map.entrySet().size()>0){
//                for (Map.Entry<String, String> entry : map.entrySet()) {
//                    log.info("{}->{}",entry.getKey(),entry.getValue());
//                }
//            }
//        }catch (Exception e){
//
//        }
        SysAclModuleMapper moduleMapper = ApplicationContextHelper.popBean(SysAclModuleMapper.class);
        SysAclModule module = moduleMapper.selectByPrimaryKey(1);
        log.info(JsonMapper.obj2String(module));
        BeanValidator.check(vo);
        return JsonData.success("test validate");
    }
}
